{% if user.is_authenticated %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="/static/favicon.ico">
    <meta name="description" content="">
    <meta name="keyword" content="">
    <meta name="author" content="root" >
    <title>弱口令扫描</title>
    <link rel="stylesheet" href="/static/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
{% include 'header.html'%}

<div class="container text-center banner">

    <!-- 扫描面板-->
    <div class="panel panel-primary">
          <div class="panel-heading">
            <h3 class="panel-title">弱口令扫描</h3>
          </div>
          <div class="panel-body">
                <!-- 扫描字段 -->
                <form class="" role="form" method="GET" action="lan_scan/" id="lan">
                  <div class="form-inline">
                    <label >Domain:</label> &nbsp;&nbsp;
                    <input type="text" class="form-control" style="width:300px;" name="url" id="url" value="127.0.0.1:3306" placeholder="192.168.1.1">
                  </div>
				  &nbsp;&nbsp;&nbsp;&nbsp;
                  <div class="form-inline">
                    <label title="选择服务类型">服务类型:</label> &nbsp;&nbsp;
                    <select class="form-control" style="width:300px;" name="server" id="server" >
						<option value="mysql">mysql</option>
						<option value="ftp">ftp</option>
						<option value="postgresql">postgresql</option>
						<option value="redis">redis</option>
						<option value="mssql">mssql</option>
						<option value="telnet">telnet</option>
                    </select>
                  </div>
				  &nbsp;&nbsp;&nbsp;&nbsp;
                  <div class="form-inline">
                    <label title="选择用户名字典">用户字典:</label> &nbsp;&nbsp;
                    <select class="form-control" style="width:300px;" name="username" id="username" >
						{% for f in weakpass %}
							{% if f == "username.txt"%}<option value={{ f}} selected = "selected" >{{ f | slice:"45" }}</option>
							{% else %}
							<option value={{ f}}>{{ f | slice:"45" }}</option>
							{% endif%}
						{% endfor %} 
                    </select>
                  </div>
				  &nbsp;&nbsp;&nbsp;&nbsp;
                  <div class="form-inline">
                    <label title="选择密码字典">密码字典:</label> &nbsp;&nbsp;
                    <select class="form-control" style="width:300px;" name="password" id="password" >
						{% for f in weakpass %}
							{% if f == "password.txt"%}<option value={{ f}} selected = "selected" >{{ f | slice:"45" }}</option>
							{% else %}
							<option value={{ f}}>{{ f | slice:"45" }}</option>
							{% endif%}
						{% endfor %}
                    </select>
                  </div>				  
				  &nbsp;&nbsp;&nbsp;&nbsp;
                  <div class="form-inline">
                    <label >线程数量:</label> &nbsp;&nbsp;
                    <input type="text" class="form-control" style="width:300px;" name="num" id="num" value="20" placeholder="192.168.1.1">
                  </div>
				  &nbsp;&nbsp;&nbsp;&nbsp;				  
				  <div class="form-inline">
				  <button type="button" class="btn btn-default" onclick="submit_scan()">Start</button> &nbsp;&nbsp;&nbsp;&nbsp;
				  </div>
                </form>
          </div>
    </div>
    <!-- 扫描面板结束 -->

<!-- 进度条-->
<div class="progress" id="scan_jindu">
  <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 0%" id="progress"> 0% 完成
  </div>
</div>

<!-- 实时添加数据 -->
<table class="table table-hover" id="info">
</table>

</div>


{% include 'footer.html' %}
<!-- js引用-->
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap.min.js"></script>

<script type="text/javascript">
//装入页面
$(window).load(function() {
	//判断是否有结果
	start();
}); 
function start(){
	$.ajax({
		url:window.location.protocol + "//" + window.location.host + "{% url 'weakpass_jindu' %}",
		type:"GET",
		dataType:'json',
		success:function(data){//ajax返回的数据
			//如果为 0 则没有结果
			if (data*1 == 0){
				//没有开始,默认隐藏进度条
				$("#scan_jindu").hide();
			}else if(data == 100){
				//刷新扫描结果
				ajax_result();
				//刷新进度条
				scan_jindu();			
			}
			else{
				//实时获取数据
				ajax_resule = self.setInterval("ajax_result()",1000);
				$("#scan_jindu").show();//显示进度条
				ajax_jindu = self.setInterval("scan_jindu()",1000);
			}			
		},	
	});
  
}
//进度条
function scan_jindu(){
  $.ajax({
       url:window.location.protocol + '//' + window.location.host + "{% url 'weakpass_jindu' %}",
       type:"GET",
       success:function(data){//ajax返回的数据
        var result = data;
        //alert("width: "+result+"%");
        //添加进度条
        $("#progress").attr("style","width: "+result+"%");
        //添加进度条 百分比 显示
        $("#progress").html(function(){
          if (result<100){
            return result + "% 完成";
          }
          else {//完成后 清空 ajax刷新计划
            if (result == 100){
              self.clearInterval(scan_jindu);
			  self.clearInterval(ajax_result);
              $("#submit").removeClass('disabled'); 
              return result + "% 完成";}
            else{
                self.clearInterval(scan_jindu);
				self.clearInterval(ajax_result);
                $("#submit").removeClass('disabled');
                return result + "网络异常 %"; }
          }
          });
        },
      });
}
//异步刷新
function submit_scan(){
	//获取表单值
	var url = $("#url").val(); //获取ip和端口
	var username = $("#username").val();   
	var password = $("#password").val();
	var server = $("#server").val();
	var num = $("#num").val();
	ajax_url = window.location.protocol + "//" + window.location.host + "{% url 'weakpass_run' %}";
	//发起扫描请求
	$.get(ajax_url+"?url="+url+"&username="+username+"&password="+password+"&server="+server+"&num="+num);
	//实时获取数据
	ajax_resule = self.setInterval("ajax_result()",1000);
	$("#scan_jindu").show();//显示进度条
	ajax_jindu = self.setInterval("scan_jindu()",1000);
}
// ajax 获取结果
function ajax_result(){
	//定时获取数据
	$.ajax({
		url:window.location.protocol + "//" + window.location.host + "{% url 'weakpass_json' %}",
		type:"GET",
		dataType:'json',
		success:function(data){//ajax返回的数据
			//alert(data);
			$("#info").html("<tr><th>服务类型</th><th>地址</th><th>账户</th><th>密码</th></tr>");//设置表哥头内容
			$.each(data,function(index,content){
				//alert(content.url);
				//判断结束了停止刷新
				if (content.vul*1 == 0){
				//alert(0);
				self.clearInterval(ajax_resule);
				self.clearInterval(ajax_jindu);
				}else{
				//alert(1);
				//会重复添加,实时刷新此处要判断td1 and td2是否重复
				$("#info").append(
					"<tr><td>" + content.server + "</td>" + 
					"<td>" + content.url + "</td>" +
					"<td>" + content.u + "</td>" +
					"<td>" + content.p + "</tr>");	
				}
			});
			
		},	
	});
}
</script>

</body>
</html>
{% else %}
<script>window.location.href="{% url 'login' %}";</script> 
{% endif %}